package com.banzhi.shop.entity.InviteShopkeeperShare;

import com.banzhi.shop.MyApp;
import com.banzhi.shop.state.URLString;
import com.banzhi.shop.utils.LoadingDialogUtils;
import com.banzhi.shop.utils.LogUtils;
import com.banzhi.shop.utils.ToastUtils;
import com.google.gson.Gson;

import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * Created by JIANGFEI on 2018/4/16.
 */

public class InviteShopKeeperImpl implements IInviteShopKeeperModel {



    @Override
    public void getData(int page,final InviteShopKeeperCallBack callBack) {
        RequestParams params = new RequestParams( URLString.hostUrl + URLString.inviteShopKeeperURL );
        params.addBodyParameter( "token", MyApp.loginMessage.getString( "token", "" ) );
        params.addBodyParameter("page", page + "");
        LogUtils.d( "999999999", MyApp.loginMessage.getString( "token", "" ) );
        x.http().post( params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                try {
                    JSONObject jsonobject = new JSONObject( result );
                    if (jsonobject.optString( "code" ).equals( "0" )) {
                        Gson gson = new Gson();
                        InviteShopkeeper_data inviteShopkeeper_data = gson.fromJson( result, InviteShopkeeper_data.class );
                        callBack.ongetDataSuccess(inviteShopkeeper_data.getRes() );
                    } else {
                        callBack.ongetDataError( jsonobject );
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }


            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                LogUtils.e("inviteShopKeeperURL", "---onError----" + throwable.toString());
                LoadingDialogUtils.dismiss();
                ToastUtils.makeToastShort("网络加载失败,请稍后再试(84)");
            }


            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {
                LoadingDialogUtils.dismiss();
            }
        } );
    }
}
